$(document).ready(function(){
/**
 * 楼层
*/
	//获取每层的offsetTop
	var offset = [];
	var now_floor;
	offset[0] = 0;

	for (i = 1; i < 5; i++) {

	    offset[i] = $("#floor-" + i).offset().top;

	}
	$('.pos-floor').hide();
	$(window).scroll(function () {
	    var scr_top = $(document).scrollTop();
	    //判断当前滚到了第几楼
	    var now_floor_array = offset.filter(function (item, index, array) {
	        if (item < scr_top) {
	            return index;
	        }
	    })
	    //判断当前楼层即数组长度
	    now_floor = now_floor_array.length;
	    //删除当前楼层外的高亮,给当前楼层增加高亮
	    $(".pos-floor li").eq(now_floor+1).addClass("active").siblings().removeClass("active");

	    if(scr_top < offset[1] - 300 || scr_top > offset[4] + 300){
	    	$('.pos-floor').hide(100);
	    }else{
	    	$('.pos-floor').show(100);
	    };
	})

	$(".pos-floor li").each(function (index, element) {
	    $(this).click(function () {  
	        if (index > 0) {
	        	var floor_number = index;
		        var sroll_height = $("#floor-" + floor_number).offset().top;
	        	$('html,body').animate({
		            scrollTop: sroll_height
		        }, 300)
	        };
	        
	    })
	});
	//楼层位置
	var floorLeft = ($(window).width() - 1200) / 2 - 58;
	$('.pos-floor').css('left',floorLeft);
	$(window).resize(function(){
		var floorLeft = ($(window).width() - 1200) / 2 - 58;
		$('.pos-floor').css('left',floorLeft);
	});	
});